<?php

// article feedback delete page
require_once 'view/common/layout.formview.php';
require_once 'view/common/layout.view.php';

require_once WACT_ROOT . 'controller/controller.inc.php';
require_once WACT_ROOT . 'controller/form.inc.php';
require_once APP_ROOT . 'model/common/form.php';

class FeedbackDeletePage extends PageController {

	var $form;


    function FeedbackDeletePage() {
        parent::PageController();


        $this->form = new FormController();

        $this->form->addChild('delete', new ButtonController(new Delegate($this, 'delete')));
        $this->form->addChild('cancel', new ButtonController(new Delegate($this, 'cancel')));
        $this->form->setDefaultChild('cancel');

        $this->form->registerOnLoadListener(new Delegate($this, 'load'));

        $this->addChild('DeleteForm', $this->form);
        $this->setDefaultChild('DeleteForm');

        $this->registerOnActivateListener(new Delegate($this, 'guard'));

        $this->setDefaultView(new Handle('LayoutFormView', array('/adm/content/feedback.delete.html')));
        $this->addView('success', new Handle('RedirectView', array('/')));
        $this->addView('cancel', new Handle('RedirectView', array('/')));
        $this->addView('notfound', new Handle('RedirectView', array('/')));
    }

    function guard(&$source, &$request, &$responseModel) {
        if (!$request->hasParameter('submission_id')) {
            print "Article feedback was not found ";
            return 'notfound';
        }
    }

    function load(&$source, &$request, &$responseModel) {
    	$submission_id = $request->getParameter('submission_id');
        $record =& SubmissionForm::getRecord($submission_id);
        if (is_null($record)) {
            return 'notfound';
        }

        $responseModel->import($record->export());
    }

    function cancel(&$source, &$request, &$responseModel) {
        return 'cancel';
    }

    function delete(&$source, &$request, &$responseModel) {
    	//print "Trying to delete...";
        if ($responseModel->isValid()) {
        	$headline = $responseModel->get('headline');
        	$form_header =  $responseModel->get('form_header');
        	$submission_id = $request->getParameter('submission_id');
        	if ($submission_id) {
            	SubmissionForm::delete($submission_id);
            	$responseModel->set('msg','The article feedback '.$form_header.' for article '.$headline.' has been deleted!');
            	return 'success';
            } else return 'notfound';
        }
    }

}


?>